package common.widget;

import java.util.ArrayList;
import java.util.List;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

public class GridViewAdapter extends BaseAdapter
{
	private Context mContext;
	private List<GridViewItem> gridViewItemList=null;
	final private int GRID_ITEM_PADDING=8;
//	private boolean forGridView=true;
	
//	public void setForGridView(boolean forGridView)
//	{
//		this.forGridView = forGridView;
//	}

	public GridViewAdapter(Context c)
	{
		mContext = c;
	}
	
	public void addGridViewItem(GridViewItem item)
	{
		if(gridViewItemList==null)
			gridViewItemList=new ArrayList<GridViewItem>();
		
		gridViewItemList.add(item);
	}
	
	public int getCount()
	{
		if(gridViewItemList==null)
			return 0;
		
		int count=gridViewItemList.size();
		return count;
	}

	public Object getItem(int position,String str)
	{
		if(gridViewItemList==null)
			return null;
		
		int count=gridViewItemList.size();
		if(position<0 && position>=count)
		{
			return null;
		}
		
		GridViewItem item=gridViewItemList.get(position);
		return item;
	}
	
	public Object getItem(int position)
	{
		//return position;
		return getItem(position,null);
	}

	public long getItemId(int position)
	{
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent)
	{
		GridViewItem item=null;
		if (convertView == null)
		{
			item=(GridViewItem)getItem(position,"");
		}
		else
		{
			item = (GridViewItem) convertView;
		}
//		test
//		TextView item=new TextView(mContext);
//		item.setText("item"+position);

		return item;
	}
}
